package com.sunyur.tailor.channel.service.outer.workflow.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sunyur.tailor.channel.common.middle.base.ChannelResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;
import com.sunyur.tailor.channel.common.middle.util.ChannelResultUtil;
import com.sunyur.tailor.channel.common.middle.util.RestTemplateUtil;
import com.sunyur.tailor.channel.service.outer.workflow.model.OuterWorkflowModel;
import com.sunyur.tailor.channel.service.outer.workflow.param.OuterWorkflowParam;
import com.sunyur.tailor.channel.service.outer.workflow.service.OuterWorkflowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Objects;


/**
 *
 * @Author 99288
 * @Description 审批流表单提交实现
 * @Param
 * @return
**/
@Slf4j
@Service("outerWorkflowService")
public class OuterWorkflowServiceImpl implements OuterWorkflowService {

    @Value("${outer.workflow}")
    private String workflowUrl;
    @Autowired
    private RestTemplateUtil restTemplateUtil;

    @Override
    public ChannelResult<Boolean> submitWorkflowForm(OuterWorkflowParam outerWorkflowParam) {
        log.info("OuterWorkflowServiceImpl submitWorkflowForm param:{}", JSON.toJSONString(outerWorkflowParam));
        if (Objects.isNull(outerWorkflowParam)) {
            return ChannelResultUtil.error(MiddleResultEnum.PARAM_NULL.getCode(), MiddleResultEnum.PARAM_NULL.getValue());
        }
        JSONObject jsonObject = restTemplateUtil.exchangeJsonPost(outerWorkflowParam, workflowUrl);
        if (Objects.nonNull(jsonObject)) {
            OuterWorkflowModel outerWorkflowModel = JSON.toJavaObject(jsonObject, OuterWorkflowModel.class);

        }
        return ChannelResultUtil.error(MiddleResultEnum.FAILED.getCode(), MiddleResultEnum.FAILED.getValue());
    }
}
